package com.promise.jokerdream.ui.settings

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.clickable
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.promise.jokerdream.database.entity.FactionFeedDemoGameConfigEntity
import com.promise.jokerdream.model.faction.FactionFeedDemoMapping
import com.promise.jokerdream.ui.components.SettingCard
import com.promise.jokerdream.ui.components.SingleSelectHashtagBottomSheet
import com.promise.jokerdream.ui.components.SelectionRow
import com.promise.jokerdream.ui.theme.AppSpacing
import com.promise.jokerdream.ui.theme.AppFontSizes

/**
 * 帮派供奉设置卡片
 */
@Composable
fun FactionFeedDemoSettingCard(
    config: FactionFeedDemoGameConfigEntity,
    onEnabledChange: (Boolean) -> Unit,
    onFeedItemNameChange: (String) -> Unit,
    modifier: Modifier = Modifier,
    onExecuteClick: (() -> Unit)? = null
) {
    var showBottomSheet by remember { mutableStateOf(false) }
    
    SettingCard(
        title = "帮派供奉",
        description = "",
        checked = config.enabledSetting,
        onCheckedChange = onEnabledChange,
        modifier = modifier,
        onExecuteClick = onExecuteClick,
        content = {
            if (config.enabledSetting) {
                Column(
                    modifier = Modifier.fillMaxWidth()
                ) {
                    // 供奉物品选择区域
                    SelectionRow(
                        label = "供奉物品：",
                        selectedText = if (config.feedItemName.isNotEmpty()) config.feedItemName else "未选择",
                        onClick = { showBottomSheet = true }
                    )
                }
            }
        }
    )
    
    // 供奉物品选择底部弹窗
    if (showBottomSheet) {
        SingleSelectHashtagBottomSheet(
            title = "选择供奉物品",
            initialText = config.feedItemName,
            placeholder = "输入物品名称",
            recommendedTags = FactionFeedDemoMapping.getAllItemNames(),
            onCancel = { showBottomSheet = false },
            onComplete = { selectedName ->
                onFeedItemNameChange(selectedName)
                showBottomSheet = false
            },
            onDismiss = { showBottomSheet = false }
        )
    }
}
